//
//  EarnTicketColCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/10.
//

import UIKit

class EarnTicketColCell: UICollectionViewCell {
    
    lazy var dayLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 10)
        label.textColor = .white
        label.backgroundColor = .init(named: "red_FE95B4")
        label.textAlignment = .center
        return label
    }()
    
    lazy var ticketImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "ticket_big")?.withRenderingMode(.alwaysTemplate))
        return image
    }()
    
    lazy var signedImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "date_ico_signed"))
        image.isHidden = true
        return image
    }()
    
    lazy var goldLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .init(named: "gray_666666")
        label.textAlignment = .center
        return label
    }()
    
    var model: TicketModel? {
        didSet {
            if let m = model {
                signedImage.isHidden = m.status != 2
                dayLabel.text = m.status == 2 ? "今天" : "第\(m.day ?? 0)天"
                goldLabel.text = "+\(m.gold ?? 0)"
                let color = UIColor.init(named: m.status == 2 ? "red_FE95B4" : ( m.status == 1 ? "red_FFB8C7" : "gray_D0D0D0"))
                dayLabel.backgroundColor = color
                dayLabel.wn_cornerWithBorder(4, 1, color!)
                wn_cornerWithBorder(4, 1, color!)
                ticketImage.tintColor = color
                dayLabel.layer.masksToBounds = true
                layer.masksToBounds = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(dayLabel)
        addSubview(ticketImage)
        addSubview(signedImage)
        addSubview(goldLabel)
        dayLabel.snp.makeConstraints { (make) in
            make.top.left.right.equalTo(0)
            make.height.equalTo(16)
        }
        ticketImage.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(dayLabel.snp.bottom).offset(8)
            make.width.height.equalTo(32)
        }
        signedImage.snp.makeConstraints { (make) in
            make.bottom.equalTo(ticketImage.snp.bottom)
            make.right.equalTo(ticketImage.snp.right)
            make.width.height.equalTo(14)
        }
        goldLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(ticketImage.snp.bottom)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
